package com.steria.workshop.android.yrapp.lib.model;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class WeatherData {

	private List<WeatherPoint> weatherPointList;
	private List<WeatherPeriod> weatherPeriodList;

	public WeatherData() {
		weatherPointList = new ArrayList<WeatherPoint>();
		weatherPeriodList = new ArrayList<WeatherPeriod>();
	}

	public WeatherPoint getWeatherPoint(Date point) {
		for (WeatherPoint weatherPoint : weatherPointList) {
			if (weatherPoint.getDate().equals(point))
				return weatherPoint;
		}
		return null;
	}
	
	public WeatherPoint getWeatherPoint(WeatherPeriod period) {
		return getWeatherPoint(period.getFrom());
	}

	public void addWeatherAtPointInTime(WeatherPoint aNewForecastPoint) {
		weatherPointList.add(aNewForecastPoint);
	}

	public void addWeatherPeriod(WeatherPeriod aNewForecastPeriod) {
		weatherPeriodList.add(aNewForecastPeriod);
	}

	public List<WeatherPeriod> getWeatherPeriods() {
		return weatherPeriodList;
	}

	public static String dateAsString(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String formattedDate = formatter.format(date);
		return formattedDate;
	}
}
